import { isIdCard, isPhoneNumber, isBankCard } from '@/utils/index'

export const formRules = reactive({
  name: [{ validator: notEmpty, msg: '请输入姓名', trigger: ['change','blur'] }],
  idCard: [{ validator: notEmpty, msg: '请输入身份证号', trigger: ['change','blur'] }],
  gender: [{ validator: notEmpty, msg: '请选择性别', trigger: ['change','blur'] }],
  birthDate: [{ validator: notEmpty, msg: '请选择出生日期', trigger: ['change','blur'] }],
  
  ethnic: [{ validator: notEmpty, msg: '请选择民族', trigger: ['change','blur'] }],
  nativePlace: [{ validator: notEmpty, msg: '请输入籍贯', trigger: ['change','blur'] }],
  politicalStatus: [{ validator: notEmpty, msg: '请选择政治面貌', trigger: ['change','blur'] }],
  maritalStatus: [{ validator: notEmpty, msg: '请选择婚姻状态', trigger: ['change','blur'] }],
  
  education: [{ validator: notEmpty, msg: '请选择学历', trigger: ['change','blur'] }],
  phone: [{ validator: notEmpty, msg: '请输入手机号', trigger: ['change','blur'] }],
  emergencyContact: [{ validator: notEmpty, msg: '请输入紧急联系人', trigger: ['change','blur'] }],
  urgentPhone: [{ validator: notEmpty, msg: '请输入紧急联系人手机号', trigger: ['change','blur'] }],

  healthStatus: [{ validator: notEmpty, msg: '请选择身体状况', trigger: ['change','blur'] }],
  bankCard: [{ validator: notEmpty, msg: '请输入银行卡号', trigger: ['change','blur'] }],
  entryTime: [{ validator: notEmpty, msg: '请选择入职时间', trigger: ['change','blur'] }],
  contractYear: [{ validator: notEmpty, msg: '请选择签约时间', trigger: ['change','blur'] }],




  departmentId: [{ validator: notEmpty, msg: '请选择部门', trigger: ['change','blur'] }],
  position: [{ validator: notEmpty, msg: '请输入岗位', trigger: ['change','blur'] }],
})



// 校验不能为空
function notEmpty(rule, value, callback) {
  if (!value) {
    return callback(new Error(rule.msg))
  }else if (rule.field === 'phone' || rule.field === 'urgentPhone') {
    phoneRules(rule, value, callback)
  } else if (rule.field === 'idCard') {
    idCardRules(rule, value, callback)
  } else if (rule.field === 'bankCard') {
    bankCardRules(rule, value, callback)
  }else{
    callback()
  }
  
  
}

function phoneRules(rule, value, callback) {
    if (!isPhoneNumber(value)) {
      return callback(new Error('请输入正确的手机号'))
    }else{
      callback()
    }
}


function idCardRules(rule, value, callback) {
    if (!isIdCard(value)) {
      return callback(new Error('请输入正确的身份证号'))
    }else{
      callback()
    }
}


function bankCardRules(rule, value, callback) {
    if (!isBankCard(value)) {
      return callback(new Error('请输入正确的银行卡号'))
    }else{
      callback()
    }
}